#include <vector>
using namespace std;
int removeDuplicates(vector<int> &nums) {
  int pos = 1;
  int count = 1;
  for (int i = 1; i < nums.size(); ++i) {
    if (nums[i] == nums[pos - 1] && count < 2) {
      nums[pos++] = nums[i];
      count++;
    } else if (nums[i] != nums[pos - 1]) {
      count = 1;
      nums[pos] = nums[i];
      pos++;
    } else if (nums[i] == nums[pos - 1] && count >= 2) {
      continue;
    }
  }
  return pos;
}